package com.moli.iov.base.remote.impl;

import com.moli.iov.base.enums.DictTypeTag;
import com.moli.iov.cache.RedisUtil;
import com.moli.iov.base.constants.DictConstants;
import com.moli.iov.base.model.dto.DictDataQueryByCodeDto;
import com.moli.iov.base.model.dto.DictDataQueryByTypeDto;
import com.moli.iov.base.model.dto.DictMap;
import com.moli.iov.base.model.dto.DictParam;
import com.moli.iov.base.model.dto.DictTypeDto;
import com.moli.iov.base.model.po.DictData;
import com.moli.iov.base.remote.IDictDataRemoteService;
import com.moli.iov.base.service.IDictDataService;
import com.moli.iov.rest.RestResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName DictDataRemoteServiceImpl
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-06-28 下午 4:48
 * @UpdateDate 2019-06-28 下午 4:48
 * @Version 1.0
 */
@Service(group = "${service.group}")
@Slf4j
public class IDictDataRemoteServiceImpl implements IDictDataRemoteService {

  @Resource
  RedisUtil redisUtil;
  @Autowired
  private IDictDataService iDictDataService;

  @Override
  public RestResponse<DictMap> getDictMap(DictParam param) {
    DictMap dto = new DictMap();
    if (param != null) {
      Map<String, String> map = new HashMap<>();
      List<String> list = redisUtil.hgetString(DictConstants.DICT_MAP_TYPE, param.get());
      if (list != null && list.size() > 0) {
        for (String value : list) {
          dto.put(value);
        }
      }
    }
    return RestResponse.success(dto);
  }

  @Override
  public RestResponse<Map<String, Map<String, String>>> queryDictMaps(DictTypeDto dictTypeDto) {
    return iDictDataService.queryDictMaps(dictTypeDto);
  }

  @Override
  public RestResponse queryValueByCode(DictDataQueryByCodeDto dictDataQueryByCodeDto) {
    return iDictDataService.queryValueByCode(dictDataQueryByCodeDto);
  }

  @Override
  public RestResponse<List<DictData>> queryListByType(
      DictDataQueryByTypeDto dictDataQueryByTypeDto) {
    return iDictDataService.queryListByType(dictDataQueryByTypeDto);
  }

  @Override
  public RestResponse<Map<String, String>> queryMapByType(
      DictDataQueryByTypeDto dictDataQueryByTypeDto) {
    return iDictDataService.queryMapByType(dictDataQueryByTypeDto);
  }

  @Override
  public RestResponse<Map<String, List<DictData>>> queryBasicDicinfos() {

    return iDictDataService.queryBasicDicinfos();

  }

  @Override
  public RestResponse<Map<String, List<DictData>>> queryBasicDicinfos(DictDataQueryByTypeDto dictDataQueryByTypeDto) {
    return iDictDataService.queryBasicDicinfos(dictDataQueryByTypeDto.getDictType());
  }

  @Override
  public RestResponse<List<DictData>> queryDictsByPcode(Integer pcode, String dictType) {
    return iDictDataService.queryDictsByPcode(pcode, dictType);
  }

  @Override
  public RestResponse<Map<String, List<DictData>>> queryAllDicts() {
    return iDictDataService.queryAllDicts();
  }

  @Override
  public RestResponse cacheAllDict() {
    return iDictDataService.cacheAllDict();
  }

  @Override
  public Map<String, Map<String, String>> getDictMaps(List<DictTypeTag> list) {
    return iDictDataService.getDictMaps( list);
  }
}
